﻿namespace Sidvall.FileSystemManager.UI.Entities
{
    [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
    public sealed partial class PathName : global::Sidvall.FileSystemManager.UI.Entities.Core.BusinessBase, global::Sidvall.FileSystemManager.Data.IPathName
    {
        #region Business Members

        #region Folder

        private string _Folder = string.Empty;
        partial void OnBeforeFolderPropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeFolderPropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterFolderPropertyChanged();
        public string Folder
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_Folder);
                OnBeforeFolderPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _Folder);
                OnBeforeFolderPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("Folder", eventData.Value, true, true, true);
                    OnAfterFolderPropertyChanged();
                }
            }
        }

        #endregion
        #region FullName

        private string _FullName = string.Empty;
        partial void OnBeforeFullNamePropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeFullNamePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterFullNamePropertyChanged();
        public string FullName
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_FullName);
                OnBeforeFullNamePropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _FullName);
                OnBeforeFullNamePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("FullName", eventData.Value, true, true, true);
                    OnAfterFullNamePropertyChanged();
                }
            }
        }

        #endregion
        #region IsFolder

        private bool _IsFolder = false;
        partial void OnBeforeIsFolderPropertyGet(Sidvall.Business.PropertyEventData<bool> eventData);
        partial void OnBeforeIsFolderPropertyChanged(Sidvall.Business.PropertyChangeEventData<bool> eventData);
        partial void OnAfterIsFolderPropertyChanged();
        public bool IsFolder
        {
            get
            {
                Sidvall.Business.PropertyEventData<bool> eventData = new Sidvall.Business.PropertyEventData<bool>(_IsFolder);
                OnBeforeIsFolderPropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<bool> eventData = new Sidvall.Business.PropertyChangeEventData<bool>(value, _IsFolder);
                OnBeforeIsFolderPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("IsFolder", eventData.Value, true, true, true);
                    OnAfterIsFolderPropertyChanged();
                }
            }
        }

        #endregion
        #region Name

        private string _Name = string.Empty;
        partial void OnBeforeNamePropertyGet(Sidvall.Business.PropertyEventData<string> eventData);
        partial void OnBeforeNamePropertyChanged(Sidvall.Business.PropertyChangeEventData<string> eventData);
        partial void OnAfterNamePropertyChanged();
        public string Name
        {
            get
            {
                Sidvall.Business.PropertyEventData<string> eventData = new Sidvall.Business.PropertyEventData<string>(_Name);
                OnBeforeNamePropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<string> eventData = new Sidvall.Business.PropertyChangeEventData<string>(value, _Name);
                OnBeforeNamePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("Name", eventData.Value, true, true, true);
                    OnAfterNamePropertyChanged();
                }
            }
        }

        #endregion
        #region PathNameId

        private System.Nullable<int> _PathNameId = null;
        partial void OnBeforePathNameIdPropertyGet(Sidvall.Business.PropertyEventData<System.Nullable<int>> eventData);
        partial void OnBeforePathNameIdPropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData);
        partial void OnAfterPathNameIdPropertyChanged();
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        public System.Nullable<int> PathNameId
        {
            get
            {
                Sidvall.Business.PropertyEventData<System.Nullable<int>> eventData = new Sidvall.Business.PropertyEventData<System.Nullable<int>>(_PathNameId);
                OnBeforePathNameIdPropertyGet(eventData);
                return eventData.Value;
            }
            internal set
            {
                Sidvall.Business.PropertyChangeEventData<System.Nullable<int>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<int>>(value, _PathNameId);
                OnBeforePathNameIdPropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("PathNameId", eventData.Value, true, true, true);
                    OnAfterPathNameIdPropertyChanged();
                }
            }
        }

        #endregion
        #region Size

        private System.Nullable<long> _Size = null;
        partial void OnBeforeSizePropertyGet(Sidvall.Business.PropertyEventData<System.Nullable<long>> eventData);
        partial void OnBeforeSizePropertyChanged(Sidvall.Business.PropertyChangeEventData<System.Nullable<long>> eventData);
        partial void OnAfterSizePropertyChanged();
        public System.Nullable<long> Size
        {
            get
            {
                Sidvall.Business.PropertyEventData<System.Nullable<long>> eventData = new Sidvall.Business.PropertyEventData<System.Nullable<long>>(_Size);
                OnBeforeSizePropertyGet(eventData);
                return eventData.Value;
            }
            set
            {
                Sidvall.Business.PropertyChangeEventData<System.Nullable<long>> eventData = new Sidvall.Business.PropertyChangeEventData<System.Nullable<long>>(value, _Size);
                OnBeforeSizePropertyChanged(eventData);
                if (!eventData.Cancel)
                {
                    LoadInstanceField("Size", eventData.Value, true, true, true);
                    OnAfterSizePropertyChanged();
                }
            }
        }

        #endregion
        #region DataRowContextStorageKey

        protected override string DataRowContextStorageKey
        {
            get
            {
                return global::Sidvall.FileSystemManager.UI.SystemContext.Current.EntityFacade.PathNameManager.GetKey(this);
            }
        }

        #endregion
        #region LoadInstanceField

        public void LoadInstanceField(string fieldName, object value, bool cascade, bool raisePropertyChanged, bool updateState)
        {
            global::Sidvall.FileSystemManager.UI.SystemContext.Current.EntityFacade.PathNameManager.LoadInstanceField(this, fieldName, value, cascade, raisePropertyChanged, updateState);
        }

        #endregion
        #region AcceptChanges

        public void AcceptChanges()
        {
            global::Sidvall.FileSystemManager.UI.SystemContext.Current.EntityFacade.PathNameManager.AcceptChanges(this);
        }

        #endregion
        #region Copy

        public PathName Copy()
        {
            return Copy(null);
        }
        partial void OnAfterCopy(PathName destination, Sidvall.Data.CopySettings settings);
        public PathName Copy(Sidvall.Data.CopySettings settings)
        {
            var item = global::Sidvall.FileSystemManager.UI.SystemContext.Current.EntityFacade.PathNameManager.Copy(this, settings);
            OnAfterCopy(item, settings);
            return item;
        }

        #endregion
        #region Import

        public void Import(global::Sidvall.FileSystemManager.Data.IPathName item)
        {
            Import(item, null);
        }
        partial void OnAfterImport(global::Sidvall.FileSystemManager.Data.IPathName source, Sidvall.Data.CopySettings settings);
        public void Import(global::Sidvall.FileSystemManager.Data.IPathName item, Sidvall.Data.CopySettings settings)
        {
            global::Sidvall.FileSystemManager.UI.SystemContext.Current.EntityFacade.PathNameManager.Import(this, item, settings);
            OnAfterImport(item, settings);
        }

        #endregion
        #region ValidateAsync

        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync()
        {
            return await ValidateAsync((Sidvall.Data.ValidationSettings)null).ConfigureAwait(false);
        }
        public async System.Threading.Tasks.Task<Sidvall.Data.BusinessRuleCollection> ValidateAsync(Sidvall.Data.ValidationSettings settings)
        {
            var context = new Sidvall.Business.ValidationContext(settings);
            await global::Sidvall.FileSystemManager.UI.SystemContext.Current.EntityFacade.PathNameManager.ValidateAsync(this, context).ConfigureAwait(false);
            await ValidateAsync(context).ConfigureAwait(false);
            return context.AllBusinessRules;
        }
        partial void OnAfterValidate(Sidvall.Data.BusinessRuleCollection itemBusinessRules, Sidvall.Business.ValidationContext context);
        public async System.Threading.Tasks.Task ValidateAsync(Sidvall.Business.ValidationContext context)
        {
            var itemBusinessRules = new Sidvall.Data.BusinessRuleCollection();
            OnAfterValidate(itemBusinessRules, context);
            await context.TaskContext.DoTaskAsync().ConfigureAwait(false);
            context.AllBusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
            var businessRulesProvider = this as Sidvall.Data.IBusinessRulesProvider;
            if (businessRulesProvider != null)
                businessRulesProvider.BusinessRules.AddRange(context.Settings.IncludeNotBrokenRules, itemBusinessRules);
        }

        #endregion
        #region Initialize

        public void Initialize()
        {
            global::Sidvall.FileSystemManager.UI.SystemContext.Current.EntityFacade.PathNameManager.Initialize(this);
        }
        public void Initialize(Sidvall.Data.InitializeSettings settings)
        {
            global::Sidvall.FileSystemManager.UI.SystemContext.Current.EntityFacade.PathNameManager.Initialize(this, settings);
        }

        #endregion
        
        #region IPathName Members

        string global::Sidvall.FileSystemManager.Data.IPathName.Folder
        {
            get
            {
                return this._Folder;
            }
            set
            {
                this._Folder = value;
            }
        }
        string global::Sidvall.FileSystemManager.Data.IPathName.FullName
        {
            get
            {
                return this._FullName;
            }
            set
            {
                this._FullName = value;
            }
        }
        bool global::Sidvall.FileSystemManager.Data.IPathName.IsFolder
        {
            get
            {
                return this._IsFolder;
            }
            set
            {
                this._IsFolder = value;
            }
        }
        string global::Sidvall.FileSystemManager.Data.IPathName.Name
        {
            get
            {
                return this._Name;
            }
            set
            {
                this._Name = value;
            }
        }
        System.Nullable<int> global::Sidvall.FileSystemManager.Data.IPathName.PathNameId
        {
            get
            {
                return this._PathNameId;
            }
            set
            {
                this._PathNameId = value;
            }
        }
        System.Nullable<long> global::Sidvall.FileSystemManager.Data.IPathName.Size
        {
            get
            {
                return this._Size;
            }
            set
            {
                this._Size = value;
            }
        }

        #endregion

        #endregion
        #region Constructors

        public PathName()
        {
        }

        public PathName(Sidvall.Data.DataRowState? dataRowState)
            : base(dataRowState)
        {
        }

        #endregion
    }
}